<template>
  <div class="right-top" ref="target"></div>
</template>

<script setup>
import { onMounted, ref, watch, defineProps } from "vue";
import * as echarts from "echarts";
const props = defineProps({
  smallLine: {
    type: Array,
  },
  dict_unusualCopy: {
    type: Array,
    required: true,
  },
});

const target = ref(null);
let mChart = null;
onMounted(() => {
  mChart = echarts.init(target.value);
  renderChart();
});
const renderChart = () => {
  let options = {
    title: {
      text: "电压曲线",
      left: 10,
      top: 10,
      textStyle: {
        color: "#fff",
      },
    },
    tooltip: {
      show: true,
    },
    xAxis: {
      show: true,
      type: "category",
      data: props.dict_unusualCopy,
      name: "时间节点",
      nameLocation: "center",
      nameTextStyle: {
        padding: [20, 0, 0, 0],
      },
    },
    yAxis: {
      type: "value",
      min: 230,
      max: 245,
      name: "用户电压值",
      nameLocation: "center",
      nameTextStyle: {
        padding: [0, 0, 20, 0],
      },
    },
    series: [
      {
        data: props.smallLine,
        type: "line",
      },
    ],
  };
  mChart.setOption(options);
};
window.addEventListener("resize", function () {
  mChart.resize();
});
watch(
  () => props.smallLine,
  () => {
    renderChart();
  }
);
</script>

<style lang="scss" scoped>
.right-top {
  width: 95%;
  height: 95%;
  padding: 20px;
}
</style>
